package gui;

import java.io.IOException;

import sistema.Sistema;

import com.trolltech.qt.gui.*;

public class MainWindow extends QWidget {

	private Sistema sistema;
	private final String IMG_PATH = "ImHereM03/img/";
	
	private final String aboutMessage = "I'mHere - Milestone 3" +
			"\nDisciplina: Sistemas de Informação I" +
			"\nProfessor: Hyggo Almeida\nMonitor: Lorena Maia" +
			"\n\n        Equipe:\nAmaury Medeiros" +
			"\nDanilo Freitas\nFelipe Vieira"+
			"\nNicholas Alexander\nPaulo Ouriques";

	public MainWindow() {
		this.setWindowTitle("I'mHere");
		this.setFixedSize(330, 500);
		QVBoxLayout geral = new QVBoxLayout();
		
		QLabel imagem = new QLabel("IMAGEM");
	
		imagem.setPixmap(new QPixmap(IMG_PATH + "welcome2.png"));
		
		geral.addWidget(imagem);
		geral.addLayout(addOptions());
		
		
		QPalette palette = new QPalette();
		QLinearGradient gradient = new QLinearGradient(0, 0, 0, this.height());
		gradient.setColorAt(0.0, new QColor("#c5c5c5"));
		gradient.setColorAt(1.0, new QColor("#616161"));
		palette.setBrush(QPalette.ColorRole.Window, new QBrush(gradient));
		this.setPalette(palette);
		
		this.setLayout(geral);
		this.sistema = new Sistema();
		this.setWindowIcon(new QIcon(IMG_PATH + "icon.png"));
	}

	private void save() {
		try {
			sistema.encerrarSistema();
		} catch (IOException e) {
			QMessageBox.critical(this, "Erro",
					"O sistema nao pode ser finalizado corretamente!");
		}
	}

	private QVBoxLayout addOptions() {
		QVBoxLayout optionsLayout = new QVBoxLayout();
	
		
		
		QPushButton loginButton = new QPushButton("Login");
		QPushButton signButton = new QPushButton("Nova Conta");
		QPushButton exitButton = new QPushButton("Sair");
		QPushButton aboutButton = new QPushButton("Sobre");

		exitButton.clicked.connect(this, "close()");
		loginButton.clicked.connect(this, "login()");
		signButton.clicked.connect(this, "newAccount()");
		aboutButton.clicked.connect(this, "about()");
		
		exitButton.clicked.connect(this, "save()");
		

		optionsLayout.addWidget(loginButton);
		optionsLayout.addWidget(signButton);
		optionsLayout.addWidget(aboutButton);
		optionsLayout.addWidget(exitButton);
	

		return optionsLayout;
	}

	private void newAccount() {
		NewAccountWindow win = new NewAccountWindow(sistema);
		win.exec();
	}

	private void login() {
		LoginWindow log = new LoginWindow(sistema);
		log.exec();
	}

	
	private void about() {
		QMessageBox.about(this, "Sobre I'mHere", aboutMessage);
	}
	public static void main(String[] args) {
		QApplication.initialize(args);

		MainWindow application = new MainWindow();
		application.show();

		QApplication.exec();
	}
}
